﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


using PowerCreator.LMS.Paper.Entiry;
using PowerCreator.LMS.Web.Paper;
using PowerCreator.LMS.Common.Script;

public partial class sysadmin_QuestionManager_EditPaperInfo :PowerCreator.LMS.Web.Base.BasePage
{
    //ManagerPaperInfo manager = new ManagerPaperInfo();

    //ManagerUserInfo userManager = new ManagerUserInfo();

    //ManagerPaperQuestion objManagerPaperQuestion = new ManagerPaperQuestion();
    ManagerPaper objManagerPaper = new ManagerPaper();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //BinderDDL();
            ViewState["PaperID"] = Request.QueryString["p"].ToString();
            //ViewState["PaperSelectType"] = Base64.Decode(Request.QueryString["py"].ToString());
            ViewState["UserID"] = GetCreatedByInfo().UserID;
            Pageload();
            InitPage();
        }
    }
    protected override void InitPage()
    {
        btnSaveNext.Text = GetLanageValueByKey("btn_AddPaperInfo_SavePaper", PowerCreator.LMS.Language.LanagetItemType.Page);
        btn_CheckQuestion.Text = GetLanageValueByKey("btn_AddPaperInfo_SelectQuestion", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnBack.Text = GetLanageValueByKey("btn_AddCourseInfo_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }
    private void Pageload()
    {
        //PaperInfo info = new PaperInfo();
        VOPaperResearch info = new VOPaperResearch();
        info = objManagerPaper.LoadPaperResearch(int.Parse(ViewState["PaperID"].ToString()));
        ViewState["PaperInfo"] = info;
        txtPaperName.Text = info.PaperResearch_Name;

        txt_StartTime.Text = info.PaperResearch_StartTime.ToShortDateString();
        txt_EndTime.Text = info.PaperResearch_EndTime.ToShortDateString();

        if (info.PaperResearch_SeeState!= 1)
        {
            rdbtn_no.Checked = true;
        }
        else
        {
            rdbtn_ok.Checked = true;
        }
        if (info.PaperResearch_ShowState == 1)
        {
            rdbtn_ShowOK.Checked = true;
        }
        else
        {
            rdbtn_ShowNO.Checked = true;
        }
        if (info.PaperResearch_BuildState == 1)
        {
            btn_CheckQuestion.Visible = false;
        }
        else
        {
            btn_CheckQuestion.Visible = true;
        }


        string search = "FKPRQuestionPaperID=" + ViewState["PaperID"].ToString();
        if (objManagerPaper.QueryPaperResearchQuestion(search).Rows.Count == 0)
        {
            btn_CheckQuestion.Visible = true;
        }
        else
        {
            btn_CheckQuestion.Visible = false;
        }



    }

    //private void BinderDDL()
    //{
    //    DataTable dt = new DataTable();
    //    dt = userManager.Query("");
    //    ddlUserList.DataSource = dt;
    //    ddlUserList.DataTextField = "UserName";
    //    ddlUserList.DataValueField = "UserID";
    //    ddlUserList.DataBind();
    //}
    private bool PageCheck()
    {
        if (string.IsNullOrEmpty(txtPaperName.Text.Trim()) | string.IsNullOrEmpty(txt_StartTime.Text.Trim()) | string.IsNullOrEmpty(txt_EndTime.Text.Trim()))
        {
            Script.Alert(this, "msg", GetLanageValueByKey("AddPaper_msg13", PowerCreator.LMS.Language.LanagetItemType.Page));
            return false;
        }
        string search = string.Format(" PaperResearch_Name='{0}' and PaperResearch_ID <> {1}", txtPaperName.Text, ViewState["PaperID"].ToString());
        if (objManagerPaper.CountPaperResearch(search) != 0)
        {
            Script.Alert(Page, "msg", GetLanageValueByKey("Msg_AddPaperInfo_checkmsg6", PowerCreator.LMS.Language.LanagetItemType.Page));
            return false;
        }
        return true;

    }
    protected void btnSaveNext_Click(object sender, EventArgs e)
    {
        if (!PageCheck())
        {
            return;
        }


        VOPaperResearch info = (VOPaperResearch)ViewState["PaperInfo"];

        info.PaperResearch_Name = txtPaperName.Text;


        if (rdbtn_ok.Checked)
        {
            info.PaperResearch_SeeState = 1;
        }
        else
        {
            info.PaperResearch_SeeState = 0;
        }
        if (rdbtn_ShowOK.Checked)
        {
            info.PaperResearch_ShowState = 1;
        }
        else
        {
            info.PaperResearch_ShowState = 0;
        }
        info.PaperResearch_selecttype = "";

        info.PaperResearch_StartTime = Convert.ToDateTime(txt_StartTime.Text);
        info.PaperResearch_EndTime = Convert.ToDateTime(txt_EndTime.Text);

        if (objManagerPaper.UpdatePaperResearch(info))
        {
            Script.Alert(GetLanageValueByKey("msg_CelueSelectQuest_shuruti23", PowerCreator.LMS.Language.LanagetItemType.Page));
        }
        else
        {
            Script.Alert(GetLanageValueByKey("msg_CelueSelectQuest_shuruti24", PowerCreator.LMS.Language.LanagetItemType.Page));
        }
        //Script.Alert(Page, "msg", manager.Update(info));
        //string url = "";
        //int urltype = int.Parse(ddlQuestionSelectType.SelectedValue);
        //if (urltype == 1)
        //{
        //    url = "SelectQuestion.aspx?p=" + Base64.Encode(ViewState["PaperID"].ToString());
        //}
        //else
        //{
        //    url = "";
        //}
        //Script.RedirectURL(url);
    }

    protected void btn_CheckQuestion_Click(object sender, EventArgs e)
    {
        string url = string.Empty;
            url = "SelectQuestion.aspx?p=" + ViewState["PaperID"].ToString();

        Script.RedirectURL(url);

    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Script.RedirectURL("ManagerPaperInfo.aspx");
    }
    protected void rdbtn_Defoult_CheckedChanged(object sender, EventArgs e)
    {
        
     
    }
    protected void rdbtn_Test_CheckedChanged(object sender, EventArgs e)
    {
       
    }
}
